package com.tao.learning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.tao.base.dictionary.ChargeType;
import com.tao.content.domain.pojo.CoursePublish;
import com.tao.learning.feignclient.ContentServiceClient;
import com.tao.learning.mapper.ChooseCourseMapper;
import com.tao.learning.model.dto.ChooseCourseDto;
import com.tao.learning.model.po.ChooseCourse;
import com.tao.learning.model.po.CourseTables;
import com.tao.learning.service.IChooseCourseService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 *
 * </p>
 *
 * @author taohongrun
 * @since 2024/11/28
 */
public class ChooseCourseService extends ServiceImpl<ChooseCourseMapper, ChooseCourse> implements IChooseCourseService {

    @Autowired
    ContentServiceClient client;

    public ChooseCourseDto addChooseCourse(String userId, Long courseId) {
        CoursePublish coursepublish = client.getCoursepublish(courseId);
        String charge = coursepublish.getCharge();
        if(charge.equals(ChargeType.Charge)){
            return addChargeCourse(userId,courseId);
        }else {
            ChooseCourseDto chooseCourseDto = addFreeCourse(userId, courseId);
            addCourseTabls(chooseCourseDto);
            return chooseCourseDto;
        }
    }

    private ChooseCourseDto addChargeCourse(String UserId, Long courseId){
        ChooseCourse chooseCourse = new ChooseCourse();
        save(chooseCourse);
        return null;
    }

    private ChooseCourseDto addFreeCourse(String UserId, Long courseId){
        ChooseCourse chooseCourse = new ChooseCourse();
        save(chooseCourse);
        return null;
    }

    private CourseTables addCourseTabls(ChooseCourse ChooseCourse){
        CourseTables courseTables = new CourseTables();
        Db.save(courseTables);
        return null;
    }
}
